﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PhotoFrame
{

  public partial class Form1 : Form
  {
    #region 保存相片
    private SaveFileDialog m_saveFileDialog;
    private FolderBrowserDialog m_FolderBrowserDialog;

    private void InitializeSaveDialog()
    {
      m_saveFileDialog = new SaveFileDialog();
      m_saveFileDialog.Filter = "PNG Files(.png)|*.png|BMP Files(.Bmp)|*.bmp";      //设置文件类型   
      m_saveFileDialog.FilterIndex = 1;                       //设置默认文件类型显示顺序   
      m_saveFileDialog.RestoreDirectory = true;               //保存对话框是否记忆上次打开的目录  
      m_FolderBrowserDialog = new FolderBrowserDialog();
      m_FolderBrowserDialog.SelectedPath = "";
    }

    private void openSavePictureDialog()
    {
      if (m_saveFileDialog.ShowDialog() == DialogResult.OK)
      {
        string exportFileName = m_saveFileDialog.FileName.ToString();
        ImageFormat fmt = ImageFormat.Png;
        if (m_saveFileDialog.FilterIndex == 2)
          fmt = ImageFormat.Bmp;

        saveAsPicture(exportFileName, fmt);
      }
    }
    private void saveAsPicture(string fullPath, ImageFormat fmt)
    {
      picture.ActiveImage.Save(fullPath, fmt);
    }
    #endregion

    private FramePictureManager _frameManager;

    public Form1()
    {
      InitializeComponent();
      InitializeSaveDialog();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      _frameManager = new FramePictureManager(this.picture);
      _frameManager.load();
      _frameManager.show();
      settingPicturePostion();
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void DragDropImage(object sender, DragEventArgs e)
    {
    
    }

    private void DragOverImage(object sender, DragEventArgs e)
    {
   
    }

    private void framePictureBox1_Load(object sender, EventArgs e)
    {

    }

    private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {

    }

    private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
    {

    }

    private void toolStripButton1_Click(object sender, EventArgs e)
    {

    }
    private void SavePictureToolStripMenuItem_Click(object sender, EventArgs e)
    {
      openSavePictureDialog();
    }

    private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
    {
      Dispose();
    }

    private void PreFrameToolStripMenuItem1_Click(object sender, EventArgs e)
    {
      _frameManager.preFrame();
      _frameManager.show();
      settingPicturePostion();
    }

    private void NextFrameToolStripMenuItem1_Click(object sender, EventArgs e)
    {
      _frameManager.nextFrame();
      _frameManager.show();
      settingPicturePostion();
    }

    private void Form1_Resize(object sender, EventArgs e)
    {
      settingPicturePostion();
    }

    private void settingPicturePostion()
    {
      int w = (this.Size.Width - picture.Width);
      if (w < 0)
        picture.Left = 0;
      else
        picture.Left = w / 2;

      int h = (this.Size.Height - picture.Height);
      if (h < 0)
        picture.Top = 0;
      else
        picture.Top = h / 2;
    }
  }
}
